package com.tuling.jvm;

/**
 * 使用以下参数，不会发生大量 GC
 * -Xms15m -Xmx15m -XX:+PrintGC -XX:+DoEscapeAnalysis -XX:+EliminateAllocations
 *
 * 使用以下参数，会发生大量GC
 * -Xms15m -Xmx15m -XX:+PrintGC -XX:-DoEscapeAnalysis -XX:+EliminateAllocations
 * -Xms15m -Xmx15m -XX:+PrintGC -XX:+DoEscapeAnalysis -XX:-EliminateAllocations
 */
public class AllotOnStack {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 1000000000; ++i) {
            alloc();
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    private static void alloc() {
        User user = new User();
        user.setName("jkson");
        user.setAge("32");
    }
}
